home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
network
/
mail
/
mail110.lzh
/
GETCMD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-25
|
5KB
|
160 lines
//=========================================================
//
// getcmd.c
//
// COMMAND getcmd(int *msgno, char *xuser, char *xfile)
//
// Prompt for a command and parse the user input.
//
// Return any msgno, user, and file specified in msgno,
// xuser, xfile.
//
// If no msgno given, set it to cmsg (current message).
// If no xfile or xuser given, set to NULL.
//
//=========================================================
// $Id: getcmd.c,v 1.3 1994/02/25 13:34:54 gbj Exp user $
/*
$Log: getcmd.c,v $
* Revision 1.3 1994/02/25 13:34:54 gbj
* Tidy-up.
*
* Revision 1.2 1994/02/08 23:32:02 gbj
* First public release.
*
* Revision 1.1 1994/02/08 03:15:10 gbj
* Initial revision
*
*/
#include "mailer.h"
COMMAND getcmd(int *msgno, char *xuser, char *xfile)
{
char *f1, *f2, *f3, *bp;
char buf[80];
char cmd, cmdstring[80];
*msgno=cmsg;
*xuser='\0';
*xfile='\0';
printf("%s>", user);
bp=fgets(buf, 79, stdin); // I want the \n
if (*buf == '\n') // Simulate \n entered only
*buf='Z'; // for UNREAD command
if (bp == NULL)
return BAD;
f1=strtok(buf, " \r\n"); // command
f2=strtok(NULL, " \r\n"); // first arg
f3=strtok(NULL, " \r\n"); // second arg
if (f1 == NULL)
return BAD;
if (*f1 == '\0')
return BAD;
strcpy(cmdstring, f1);
cmd=cmdstring[0];
switch (cmd)
{
case 'd':
case 'r':
case 'u':
case 'p':
case 'h':
if (f2)
if (*f2)
*msgno=atoi(f2);
else
*msgno=cmsg;
else
*msgno=cmsg;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
*msgno=atoi(f1);
break;
case 'm':
if (f2)
if (*f2)
strcpy(xuser, f2);
break;
case 't':
if (f2)
if (*f2)
strcpy(xuser, f2);
if (f3)
if (*f3)
strcpy(xfile, f3);
break;
case 'f':
if (f2)
if (*f2)
strcpy(xuser, f2);
if (f3)
if (*f3)
*msgno=atoi(f3);
else
*msgno=cmsg;
break;
case 's':
case 'w':
case 'n':
if (f2)
if (*f2)
strcpy(xfile, f2);
break;
case 'Z': break;
case '?': break;
default: break;
}
switch (cmd)
{
case 'd': return DELETE;
case 'm': return MAIL;
case 's': return SAVE;
case 'w': return WRITE;
case 't': return MAILFILE;
case 'r': return REPLY;
case 'f': return FORWARD;
case 'u': return UNDELETE;
case '+': return NEXT;
case '-': return PREV;
case 'p': return PRINT;
case 'h': return HEADER;
case 'l': return LIST;
case 'n': return NEW;
case 'x': return QUITX;
case 'q': return QUIT;
case '?': return HELP;
case 'Z': return UNREAD;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': return READ;
default: return BAD;
}
return BAD;
}